package com.iwinding.ladygg.ui.act;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.iwinding.ladygg.R;
import com.jp.wheelview.WheelView;

import java.util.ArrayList;

/**
 * Created by hezhiyong on 2017/3/20.
 */

public class WheelActivity extends BaseActivity implements View.OnClickListener{

    public static final String WHEELSELECTSTR = "WheelSelectStr";
    public static final String WHEELSELECTDATA = "WheelSelectDATA";

    private TextView mTvCanel;
    private TextView mTvOK;
    private WheelView mWheelView;

    private String data_str = null;
    private ArrayList<String> data;

    @Override
    protected int getLayoutID() {
        return R.layout.icane_dialog_wheelbase;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        data_str = getIntent().getStringExtra(WHEELSELECTSTR);
        data = getIntent().getStringArrayListExtra(WHEELSELECTDATA);

        initView();
    }




    void initView(){
        mHead.setVisibility(View.GONE);

        mWheelView = (WheelView) findViewById(R.id.wheelview);
        mTvCanel = (TextView) findViewById(R.id.icane_cancel);
        mTvOK = (TextView) findViewById(R.id.icane_ok);

        mTvCanel.setOnClickListener(this);
        mTvOK.setOnClickListener(this);
        mWheelView.setData(data);
        mWheelView.setDefault(data.indexOf(data_str));
    }


    @Override
    public void onClick(View v) {
        if(mWheelView.isScrolling()){
            return;
        }
        switch (v.getId()){
            case R.id.icane_cancel:
                setResult(RESULT_CANCELED);
                finish();
                break;
            case R.id.icane_ok:
                String str = mWheelView.getSelectedText();
                Intent data = new Intent();
                data.putExtra(WHEELSELECTSTR,str);
                setResult(RESULT_OK,data);
                finish();
                break;
        }
    }
}
